/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package im.numgenerator;
import im.general.Config;
import java.util.Random;
/**
 *
 * @author Giovanni
 */
public class PseudoRandomGenerator {

    //private final static long seed=Config.SEED_DISTR;
    private long seed;
    private Random r;


    public PseudoRandomGenerator(long seed) {
         this.seed = seed;
         r= new Random();
         r.setSeed(seed);
    }

    public void init(){
         r= new Random();
         r.setSeed(this.seed);
    }

    public void init(long seed){
         r= new Random();
         r.setSeed(seed);
    }

    public double getGaussian(double a,double b){
        return a+b*r.nextGaussian();
    }

    public double getUniform(){
        return r.nextDouble();
    }

    public int getUniformInt(int max){
        return r.nextInt(max);
    }
    
    public double getPoisson(double c) { // c is the intensity
       double x=0.0;
       double t=0.0;
       for (;;) {
          //t -= Math.log(Math.random())/c;
           t -= Math.log(r.nextDouble())/c;
          //if (t > 1.0)
              //return x;
           if (t > 0.0)
              return t;
          x++;
        }
    }

   public long getNextSeed(){
        return r.nextLong();
    }

}
